﻿#region

using System.Text.RegularExpressions;

#endregion

namespace Radovici.Ctrls
{
    public static class HtmlHelper
    {
        private const string JWVT =
            @"<OBJECT id=""{1}"" style=""width:100%;height:100%;"" width=""100%"" height=""100%"" type=""application/x-shockwave-flash""
    data=""{0}"" src=""http://services.radovici.com/player.swf"">
	<PARAM NAME=""Movie"" VALUE=""http://services.radovici.com/player.swf""/>
    <PARAM NAME=""FlashVars"" VALUE=""{0}""/>
	<PARAM NAME=""Quality"" VALUE=""low""/>
	<PARAM NAME=""AllowScriptAccess"" VALUE=""always""/>
	<PARAM NAME=""AllowFullScreen"" VALUE=""true""/>
</OBJECT>";

        private const string PZVT =
            @"<OBJECT id=""{1}"" style=""width:100%;height:100%;"" width=""100%"" height=""100%"" type=""application/x-shockwave-flash"">
	<PARAM NAME=""Movie"" VALUE=""http://www.pornzapp.com/player.swf?config={{embedded:true,
    baseURL:'http://www.pornzapp.com',initialScale:'scale',videoFile:'{0}',
    bufferLength:1,showMenu:true,bufferBarColor2:'0x212121',bufferBarColor1:'0x212121',bufferingAnimationColor:'0xffffff',
    controlBarBackgroundColor:'0x333333',timeDisplayFontColor:'0xcccccc',controlBarGloss:'none',
    watermarkLinkUrl:'http://www.pornzapp.com',watermarkUrl:'http://www.pornzapp.com/images/watermark.gif',showWatermark:'always',
    autoBuffering:false,autoPlay:true,showOnLoadBegin:true}}""/>
	<PARAM NAME=""Quality"" VALUE=""low""/>
	<PARAM NAME=""AllowScriptAccess"" VALUE=""always""/>
	<PARAM NAME=""AllowFullScreen"" VALUE=""true""/>
</OBJECT>";

        private const string VT =
            @"<OBJECT id=""{1}"" style=""width:100%;height:100%;"" width=""100%"" height=""100%"" type=""application/x-shockwave-flash""
    data=""{0}"">
	<PARAM NAME=""Movie"" VALUE=""{0}""/>
	<PARAM NAME=""Quality"" VALUE=""low""/>
	<PARAM NAME=""AllowScriptAccess"" VALUE=""always""/>
	<PARAM NAME=""AllowFullScreen"" VALUE=""true""/>
</OBJECT>";

        public static string GetPornZappVideoHtml(string url)
        {
            return GetPornZappVideoHtml(url, string.Empty);
        }

        public static string GetPornZappVideoHtml(string url, string id)
        {
            return string.Format(PZVT, url, id);
        }

        public static string GetFlashVideoHtml(string url)
        {
            return GetFlashVideoHtml(url, string.Empty);
        }

        public static string GetFlashVideoHtml(string url, string id)
        {
            return string.Format(JWVT, url, id);
        }

        public static string GetVideoHtml(string url)
        {
            return GetVideoHtml(url, string.Empty);
        }

        public static string GetVideoHtml(string url, string id)
        {
            return string.Format(VT, url, id);
        }

        public static string ParseCode(string text)
        {
            return text.Replace("\n", "</br>");
        }

        public static string ParseBBCode(string text)
        {
            var r = new Regex(@"\[youtube:.+\](.+)\[/youtube:.+\]");
            Match m = r.Match(text);
            if (m.Success)
            {
                string bbcode = m.Value;
                foreach (Group g in m.Groups)
                {
                    string youtube = g.Value;
                    if (bbcode != youtube)
                    {
                        string youtubeUrl = string.Format("http://www.youtube.com/v/{0}", youtube);
                        text = text.Replace(bbcode, GetVideoHtml(youtubeUrl));
                    }
                }
            }
            return text;
        }
    }
}